package com.ctrip.study.refactor.extractMethod;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Customer {
	
	private List<Order> _orders = new ArrayList<Order>();
	
	private String _name;
	
	public Customer(String name){
		_name = name;
	}
	
	public List<Order> get_orders() {
		return _orders;
	}

	public void set_orders(List<Order> _orders) {
		this._orders = _orders;
	}

	public String get_name() {
		return _name;
	}

	public void set_name(String _name) {
		this._name = _name;
	}

	void printOwing(int previousAmount) {
		// print banner
		printBanner();
		// calculate outstanding
		double outstanding = getOutStanding(previousAmount * 1.5);
		// print detail
		printDetail(outstanding);
	}

	public double getOutStanding(double initialValue) {
		double result = initialValue;
		Iterator<Order> e = _orders.iterator();
		while (e.hasNext()) {
			Order each = e.next();
			result += each.getAmount();
		}
		return result;
	}

	public void printDetail(double outstanding) {
		System.out.println("name: " + _name);
		System.out.println("amount: " + outstanding);
	}

	
	public void printBanner() {
		System.out.println("**************************");
		System.out.println("***** Customer Owes ******");
		System.out.println("**************************");
	}

}
